package com.xy.modulemain.adapter

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import androidx.viewpager.widget.PagerAdapter
import com.xy.modulemain.viewpage.ItemFragment

/**
 * @ClassName FragmentViewPageAdapter
 * @Author xy
 * @Date 2021/8/20 9:52
 * @Description ViewPager 适配器
 */
class FragmentViewPageAdapter(fm: FragmentManager):FragmentPagerAdapter(fm) {
    var fragmentList = mutableListOf<Fragment>()
    var titleList = mutableListOf<String>()
//    constructor(fm: FragmentManager,fragmentList:MutableList<Fragment>,titleList:MutableList<String>):this(fm){
//        this.fragmentList = fragmentList
//        this.titleList = titleList
//    }

    fun setData(titleList: MutableList<String>){
        fragmentList.clear()
        titleList.forEach {
            fragmentList.add(ItemFragment(it+"id",it))
        }
        this.titleList = titleList
    }

    override fun getCount(): Int {
        return fragmentList.size
    }

    override fun getItem(position: Int): Fragment {
        return fragmentList[position]
    }

    override fun getPageTitle(position: Int): CharSequence? {
        return titleList[position]
    }

    override fun getItemPosition(`object`: Any): Int {
        return PagerAdapter.POSITION_NONE
    }


}